<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/
if($_SESSION['loggedIn'] == 0 && !isset($adminPage)){
include('../includes/auth.inc.php');
}

?>

<?php
// keywords created report
if (isset($_POST['kg_updated'])) {
echo '<fieldset><strong style="color:green">Keywords Created</strong></fieldset>';
}
?>

<form action="index.php?ad=kg" method="post" name="showOptions">

<fieldset>
<legend>Keyword Settings</legend>

<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td align="left" valign="top">
<label for="kgPs">Product Keywords:</label>
</td>
<td align="left" valign="top">
<input name="kg_ps" type="text" id="kgPs" class="adminInput" value="" /><br />
(eg. keyword1,keyword2,keyword3 etc. separated by commas with no space)
</td>
</tr>
<tr>
<td align="left" valign="top">
<label for="kgAdd">Add Text:</label>
</td>
<td align="left" valign="top">
<input name="kg_add" type="text" id="kgAdd" class="adminInput" />
<select name="kg_ba">
<option value="before">Before Keywords</option>
<option value="after">After Keywords</option>
</select>
</td>
</tr>
</table>

</fieldset>



<fieldset>
<input type="hidden" name="kg_updated" value="yes" />
<input value="Generate Keywords" type="submit" class="padSubmit" />
</fieldset>
</form>

<?php if (isset($_POST['kg_updated'])) { ?>

<form action="index.php?ad=kg" method="post" name="KeywordsGen">

<fieldset>
<legend>Generated Keywords</legend>

<textarea name="keywordsGenerated" cols="80" rows="4">
<?php
$pieces = explode(",", $_POST['kg_ps']);
$kp = count($pieces);
	for ($i = 0; $i < $kp; $i++) {
	$handler .= "prodCategory LIKE '%".noquote_smart($pieces[$i])."%' OR prodBrand LIKE '%".noquote_smart($pieces[$i])."%' OR prodName LIKE '%".noquote_smart($pieces[$i])."%' OR prodDescription LIKE '%".noquote_smart($pieces[$i])."%' OR prodPromoText LIKE '%".noquote_smart($pieces[$i])."%'";
		if ($i != $kp-1) {
		$handler .= " OR ";
		} else {
		$handler .= ")";
		}
	}
$sql = "SELECT * FROM affiliSt_products1 WHERE ($handler  ORDER BY prodID ASC";
$getContent = mysql_query($sql, $databaseConnect) or die(mysql_error());
$content = mysql_fetch_assoc($getContent); 

if (isset($_POST['kg_add']) && $_POST['kg_ba'] == 'before') {
$beforehandler = $_POST['kg_add'];
$afterhandler = "";
} else if (isset($_POST['kg_add']) && $_POST['kg_ba'] == 'after') {
$beforehandler = "";
$afterhandler = $_POST['kg_add'];
} else {
$beforehandler = "";
$afterhandler = "";
}
do {
echo $beforehandler.$content['prodName'].$afterhandler."\n";
if ($content['prodBrand'] != NULL) {
echo $beforehandler.$content['prodBrand']." ".$content['prodName'].$afterhandler."\n";
}
if ($content['prodCategory'] != NULL) {
echo $beforehandler.$content['prodCategory']." ".$content['prodName'].$afterhandler."\n";
}
if ($content['prodCategory'] != NULL && $content['prodBrand'] != NULL) {
echo $beforehandler.$content['prodCategory']." ".$content['prodBrand']." ".$content['prodName'].$afterhandler."\n";
}
} while ($content = mysql_fetch_assoc($getContent));
?>
</textarea>


</fieldset>

</form>



<?php } ?>
